/**
 * 
 */
package co.unipiloto.identify.camera;

import java.io.IOException;

import co.unipiloto.identificador.R;
import co.unipiloto.identificador.R.id;
import co.unipiloto.identificador.R.layout;

import android.app.Activity;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;

/**
 * @author David
 *
 */
public class CameraView extends Activity implements SurfaceHolder.Callback{
	private boolean mPreviewRunning=true;
	private SurfaceHolder mSurfaceHolder;
	private SurfaceView mSurfaceView ;
	private Camera mCamera;
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		getWindow().setFormat(PixelFormat.TRANSLUCENT);

		requestWindowFeature(Window.FEATURE_NO_TITLE);

		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

		WindowManager.LayoutParams.FLAG_FULLSCREEN);

		setContentView(R.layout.camera_surface);

		mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);

		mSurfaceHolder = mSurfaceView.getHolder();

		mSurfaceHolder.addCallback(this);

		mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);


		}

	
	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int w,
			int h) {
		if (mPreviewRunning) {

			mCamera.stopPreview();

			}

			Camera.Parameters p = mCamera.getParameters();

			p.setPreviewSize(w, h);

			mCamera.setParameters(p);

			try {

			mCamera.setPreviewDisplay(holder);

			} catch (IOException e) {


			e.printStackTrace();

			}

			mCamera.startPreview();

			mPreviewRunning = true;
		
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		mCamera = Camera.open();
		
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		mCamera.stopPreview();
		mPreviewRunning = false;
		mCamera.release();
		
	}

	Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {

		public void onPictureTaken(byte[] imageData, Camera c) {


		}

		};



}
